home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 22 / AACD 22.iso / AACD / Online / Apache / include / php / Zend / zend_API.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-12-13  |  16.5 KB  |  427 lines

  1. /*
  2.    +----------------------------------------------------------------------+
  3.    | Zend Engine                                                          |
  4.    +----------------------------------------------------------------------+
  5.    | Copyright (c) 1998-2000 Zend Technologies Ltd. (http://www.zend.com) |
  6.    +----------------------------------------------------------------------+
  7.    | This source file is subject to version 0.92 of the Zend license,     |
  8.    | that is bundled with this package in the file LICENSE, and is        | 
  9.    | available at through the world-wide-web at                           |
  10.    | http://www.zend.com/license/0_92.txt.                                |
  11.    | If you did not receive a copy of the Zend license and are unable to  |
  12.    | obtain it through the world-wide-web, please send a note to          |
  13.    | license@zend.com so we can mail you a copy immediately.              |
  14.    +----------------------------------------------------------------------+
  15.    | Authors: Andi Gutmans <andi@zend.com>                                |
  16.    |          Zeev Suraski <zeev@zend.com>                                |
  17.    +----------------------------------------------------------------------+
  18. */
  19.  
  20.  
  21. #ifndef ZEND_API_H
  22. #define ZEND_API_H
  23.  
  24. #include "modules.h"
  25. #include "zend_list.h"
  26. #include "zend_fast_cache.h"
  27. #include "zend_operators.h"
  28. #include "zend_variables.h"
  29. #include "zend_execute.h"
  30.  
  31. #define ZEND_FN(name) zend_if_##name
  32. #define ZEND_NAMED_FUNCTION(name) void name(INTERNAL_FUNCTION_PARAMETERS)
  33. #define ZEND_FUNCTION(name) ZEND_NAMED_FUNCTION(ZEND_FN(name))
  34.  
  35. #define ZEND_NAMED_FE(zend_name, name, arg_types) { #zend_name, name, arg_types },
  36. #define ZEND_FE(name, arg_types) ZEND_NAMED_FE(name, ZEND_FN(name), arg_types)
  37. #define ZEND_FALIAS(name, alias, arg_types) ZEND_NAMED_FE(name, ZEND_FN(alias), arg_types)
  38.  
  39. #define ZEND_MINIT(module)       zend_minit_##module
  40. #define ZEND_MSHUTDOWN(module)   zend_mshutdown_##module
  41. #define ZEND_RINIT(module)       zend_rinit_##module
  42. #define ZEND_RSHUTDOWN(module)   zend_rshutdown_##module
  43. #define ZEND_MINFO(module)       zend_info_##module
  44. #define ZEND_GINIT(module)       zend_ginit_##module
  45. #define ZEND_GSHUTDOWN(module)   zend_gshutdown_##module
  46.  
  47. #define ZEND_MINIT_FUNCTION(module)      int ZEND_MINIT(module)(INIT_FUNC_ARGS)
  48. #define ZEND_MSHUTDOWN_FUNCTION(module)  int ZEND_MSHUTDOWN(module)(SHUTDOWN_FUNC_ARGS)
  49. #define ZEND_RINIT_FUNCTION(module)      int ZEND_RINIT(module)(INIT_FUNC_ARGS)
  50. #define ZEND_RSHUTDOWN_FUNCTION(module)  int ZEND_RSHUTDOWN(module)(SHUTDOWN_FUNC_ARGS)
  51. #define ZEND_MINFO_FUNCTION(module)      void ZEND_MINFO(module)(ZEND_MODULE_INFO_FUNC_ARGS)
  52. #define ZEND_GINIT_FUNCTION(module)      int ZEND_GINIT(module)(GINIT_FUNC_ARGS)
  53. #define ZEND_GSHUTDOWN_FUNCTION(module)  int ZEND_GSHUTDOWN(module)(void)
  54.  
  55. #define ZEND_GET_MODULE(name) \
  56.     ZEND_DLEXPORT zend_module_entry *get_module(void) { return &name##_module_entry; }
  57.  
  58. #define ZEND_BEGIN_MODULE_GLOBALS(module_name)        \
  59.     typedef struct _zend_##module_name##_globals {
  60. #define ZEND_END_MODULE_GLOBALS(module_name)        \
  61.     } zend_##module_name##_globals;
  62.  
  63. #ifdef ZTS
  64.  
  65. #define ZEND_DECLARE_MODULE_GLOBALS(module_name)                            \
  66.     static ts_rsrc_id module_name##_globals_id;
  67. #define ZEND_INIT_MODULE_GLOBALS(module_name, globals_ctor, globals_dtor)    \
  68.     module_name##_globals_id = ts_allocate_id(sizeof(zend_##module_name##_globals), (ts_allocate_ctor) globals_ctor, (ts_allocate_dtor) globals_dtor);
  69.  
  70. #else
  71.  
  72. #define ZEND_DECLARE_MODULE_GLOBALS(module_name)                            \
  73.     static zend_##module_name##_globals module_name##_globals;
  74. #define ZEND_INIT_MODULE_GLOBALS(module_name, globals_ctor, globals_dtor)    \
  75.     globals_ctor(&module_name##_globals);
  76.  
  77. #endif
  78.  
  79.  
  80.  
  81. #define INIT_CLASS_ENTRY(class_container, class_name, functions)    \
  82.     {                                                                \
  83.         class_container.name = strdup(class_name);                    \
  84.         class_container.name_length = sizeof(class_name)-1;            \
  85.         class_container.builtin_functions = functions;                \
  86.         class_container.handle_function_call = NULL;                \
  87.         class_container.handle_property_get = NULL;                    \
  88.         class_container.handle_property_set = NULL;                    \
  89.     }
  90.  
  91. #define INIT_OVERLOADED_CLASS_ENTRY(class_container, class_name, functions, handle_fcall, handle_propget, handle_propset) \
  92.     {                                                            \
  93.         class_container.name = strdup(class_name);                \
  94.         class_container.name_length = sizeof(class_name)-1;        \
  95.         class_container.builtin_functions = functions;            \
  96.         class_container.handle_function_call = handle_fcall;    \
  97.         class_container.handle_property_get = handle_propget;    \
  98.         class_container.handle_property_set = handle_propset;    \
  99.     }
  100.  
  101.  
  102.  
  103. int zend_next_free_module(void);
  104.  
  105. ZEND_API int zend_get_parameters(int ht, int param_count, ...);
  106. ZEND_API int zend_get_parameters_array(int ht, int param_count, zval **argument_array);
  107. ZEND_API int zend_get_parameters_ex(int param_count, ...);
  108. ZEND_API int zend_get_parameters_array_ex(int param_count, zval ***argument_array);
  109.  
  110. ZEND_API int ParameterPassedByReference(int ht, uint n);
  111.  
  112. int zend_register_functions(zend_function_entry *functions, HashTable *function_table, int type);
  113. void zend_unregister_functions(zend_function_entry *functions, int count, HashTable *function_table);
  114. ZEND_API int zend_register_module(zend_module_entry *module_entry);
  115.  
  116. ZEND_API zend_class_entry *zend_register_internal_class(zend_class_entry *class_entry);
  117. ZEND_API zend_class_entry *zend_register_internal_class_ex(zend_class_entry *class_entry, zend_class_entry *parent_ce, char *parent_name);
  118.  
  119. ZEND_API zend_module_entry *zend_get_module(int module_number);
  120. ZEND_API int zend_disable_function(char *function_name, uint function_name_length);
  121.  
  122. ZEND_API void wrong_param_count(void);
  123.  
  124. #define getThis() (this_ptr)
  125.  
  126. #define WRONG_PARAM_COUNT                    ZEND_WRONG_PARAM_COUNT()
  127. #define WRONG_PARAM_COUNT_WITH_RETVAL(ret)    ZEND_WRONG_PARAM_COUNT_WITH_RETVAL(ret)
  128. #define ARG_COUNT(dummy)    (ht)
  129. #define ZEND_NUM_ARGS()        (ht)
  130. #define ZEND_WRONG_PARAM_COUNT()                    { wrong_param_count(); return; }
  131. #define ZEND_WRONG_PARAM_COUNT_WITH_RETVAL(ret)        { wrong_param_count(); return ret; }
  132.  
  133. #ifndef ZEND_WIN32
  134. #define DLEXPORT
  135. #endif
  136.  
  137. ZEND_API int zend_startup_module(zend_module_entry *module);
  138.  
  139. #define array_init(arg)            _array_init((arg) ZEND_FILE_LINE_CC)
  140. #define object_init(arg)        _object_init((arg) ZEND_FILE_LINE_CC)
  141. #define object_init_ex(arg, ce)    _object_init_ex((arg), (ce) ZEND_FILE_LINE_CC)
  142. ZEND_API int _array_init(zval *arg ZEND_FILE_LINE_DC);
  143. ZEND_API int _object_init(zval *arg ZEND_FILE_LINE_DC);
  144. ZEND_API int _object_init_ex(zval *arg, zend_class_entry *ce ZEND_FILE_LINE_DC);
  145.  
  146. /* no longer supported */
  147. ZEND_API int add_assoc_function(zval *arg, char *key,void (*function_ptr)(INTERNAL_FUNCTION_PARAMETERS));
  148.  
  149. ZEND_API int add_assoc_long(zval *arg, char *key, long n);
  150. ZEND_API int add_assoc_unset(zval *arg, char *key);
  151. ZEND_API int add_assoc_bool(zval *arg, char *key, int b);
  152. ZEND_API int add_assoc_resource(zval *arg, char *key, int r);
  153. ZEND_API int add_assoc_double(zval *arg, char *key, double d);
  154. ZEND_API int add_assoc_string(zval *arg, char *key, char *str, int duplicate);
  155. ZEND_API int add_assoc_stringl(zval *arg, char *key, char *str, uint length, int duplicate);
  156.  
  157. ZEND_API int add_index_long(zval *arg, uint idx, long n);
  158. ZEND_API int add_index_unset(zval *arg, uint idx);
  159. ZEND_API int add_index_bool(zval *arg, uint idx, int b);
  160. ZEND_API int add_index_resource(zval *arg, uint idx, int r);
  161. ZEND_API int add_index_double(zval *arg, uint idx, double d);
  162. ZEND_API int add_index_string(zval *arg, uint idx, char *str, int duplicate);
  163. ZEND_API int add_index_stringl(zval *arg, uint idx, char *str, uint length, int duplicate);
  164.  
  165. ZEND_API int add_next_index_long(zval *arg, long n);
  166. ZEND_API int add_next_index_unset(zval *arg);
  167. ZEND_API int add_next_index_bool(zval *arg, int b);
  168. ZEND_API int add_next_index_resource(zval *arg, int r);
  169. ZEND_API int add_next_index_double(zval *arg, double d);
  170. ZEND_API int add_next_index_string(zval *arg, char *str, int duplicate);
  171. ZEND_API int add_next_index_stringl(zval *arg, char *str, uint length, int duplicate);
  172.  
  173. ZEND_API int add_get_index_long(zval *arg, uint idx, long l, void **dest);
  174. ZEND_API int add_get_index_double(zval *arg, uint idx, double d, void **dest);
  175. ZEND_API int add_get_assoc_string(zval *arg, char *key, char *str, void **dest, int duplicate);
  176. ZEND_API int add_get_assoc_stringl(zval *arg, char *key, char *str, uint length, void **dest, int duplicate);
  177. ZEND_API int add_get_index_string(zval *arg, uint idx, char *str, void **dest, int duplicate);
  178. ZEND_API int add_get_index_stringl(zval *arg, uint idx, char *str, uint length, void **dest, int duplicate);
  179.  
  180. ZEND_API int call_user_function(HashTable *function_table, zval **object_pp, zval *function_name, zval *retval_ptr, int param_count, zval *params[]);
  181. ZEND_API int call_user_function_ex(HashTable *function_table, zval **object_pp, zval *function_name, zval **retval_ptr_ptr, int param_count, zval **params[], int no_separation, HashTable *symbol_table);
  182.  
  183. ZEND_API int add_property_long(zval *arg, char *key, long l);
  184. ZEND_API int add_property_unset(zval *arg, char *key);
  185. ZEND_API int add_property_bool(zval *arg, char *key, int b);
  186. ZEND_API int add_property_resource(zval *arg, char *key, long r);
  187. ZEND_API int add_property_double(zval *arg, char *key, double d);
  188. ZEND_API int add_property_string(zval *arg, char *key, char *str, int duplicate);
  189. ZEND_API int add_property_stringl(zval *arg, char *key, char *str, uint length, int duplicate);
  190.  
  191. ZEND_API int zend_set_hash_symbol(zval *symbol, char *name, int name_length,
  192.                                   int is_ref, int num_symbol_tables, ...);
  193.  
  194. #define add_method(arg,key,method)    add_assoc_function((arg),(key),(method))
  195.  
  196. #define ZVAL_RESOURCE(z,l) {            \
  197.         (z)->type = IS_RESOURCE;        \
  198.         (z)->value.lval = l;            \
  199.     }
  200. #define ZVAL_BOOL(z,b) {                \
  201.         (z)->type = IS_BOOL;            \
  202.         (z)->value.lval = b;            \
  203.     }
  204. #define ZVAL_NULL(z) {                    \
  205.         (z)->type = IS_NULL;            \
  206.     }
  207. #define ZVAL_LONG(z,l) {                \
  208.         (z)->type = IS_LONG;            \
  209.         (z)->value.lval = l;            \
  210.     }
  211. #define ZVAL_DOUBLE(z,d) {                \
  212.         (z)->type = IS_DOUBLE;            \
  213.         (z)->value.dval = d;            \
  214.     }
  215. #define ZVAL_STRING(z,s,duplicate) {    \
  216.         char *__s=(s);                    \
  217.         (z)->value.str.len = strlen(__s);    \
  218.         (z)->value.str.val = (duplicate?estrndup(__s,(z)->value.str.len):__s);    \
  219.         (z)->type = IS_STRING;            \
  220.     }
  221. #define ZVAL_STRINGL(z,s,l,duplicate) {    \
  222.         char *__s=(s); int __l=l;        \
  223.         (z)->value.str.len = __l;        \
  224.         (z)->value.str.val = (duplicate?estrndup(__s,__l):__s);    \
  225.         (z)->type = IS_STRING;            \
  226.     }
  227.  
  228. #define ZVAL_EMPTY_STRING(z) {            \
  229.         (z)->value.str.len = 0;          \
  230.         (z)->value.str.val = empty_string; \
  231.         (z)->type = IS_STRING;            \
  232.     }
  233.  
  234. #define ZVAL_FALSE  { (z)->value.lval = 0;  (z)->type = IS_BOOL; }
  235. #define ZVAL_TRUE   { (z)->value.lval = 1;  (z)->type = IS_BOOL; }
  236.  
  237. #define RETVAL_RESOURCE(l) {            \
  238.         return_value->type = IS_RESOURCE;\
  239.         return_value->value.lval = l;    \
  240.     }
  241. #define RETVAL_BOOL(b) {                \
  242.         return_value->type = IS_BOOL;    \
  243.         return_value->value.lval = b;    \
  244.     }
  245. #define RETVAL_NULL() {                    \
  246.         return_value->type = IS_NULL;    \
  247.     }
  248. #define RETVAL_LONG(l) {                \
  249.         return_value->type = IS_LONG;    \
  250.         return_value->value.lval = l;    \
  251.     }
  252. #define RETVAL_DOUBLE(d) {                \
  253.         return_value->type = IS_DOUBLE;    \
  254.         return_value->value.dval = d;    \
  255.     }
  256. #define RETVAL_STRING(s,duplicate) {    \
  257.         char *__s=(s);                    \
  258.         return_value->value.str.len = strlen(__s);    \
  259.         return_value->value.str.val = (duplicate?estrndup(__s,return_value->value.str.len):__s);    \
  260.         return_value->type = IS_STRING;    \
  261.     }
  262. #define RETVAL_STRINGL(s,l,duplicate) {        \
  263.         char *__s=(s); int __l=l;            \
  264.         return_value->value.str.len = __l;    \
  265.         return_value->value.str.val = (duplicate?estrndup(__s,__l):__s);    \
  266.         return_value->type = IS_STRING;        \
  267.     }
  268.  
  269. #define RETVAL_EMPTY_STRING() {                \
  270.         return_value->value.str.len = 0;      \
  271.         return_value->value.str.val = empty_string; \
  272.         return_value->type = IS_STRING;        \
  273.     }
  274.  
  275. #define RETVAL_FALSE  { return_value->value.lval = 0;  return_value->type = IS_BOOL; }
  276. #define RETVAL_TRUE   { return_value->value.lval = 1;  return_value->type = IS_BOOL; }
  277.  
  278. #define RETURN_RESOURCE(l) {            \
  279.         return_value->type = IS_RESOURCE;\
  280.         return_value->value.lval = l;    \
  281.         return;                            \
  282.     }
  283.  
  284. #define RETURN_BOOL(b) {                \
  285.         return_value->type = IS_BOOL;    \
  286.         return_value->value.lval = b;    \
  287.         return;                            \
  288.     }
  289.  
  290. #define RETURN_NULL() {                \
  291.         return_value->type = IS_NULL;    \
  292.         return;                            \
  293.     }
  294.  
  295. #define RETURN_LONG(l) {                \
  296.         return_value->type = IS_LONG;    \
  297.         return_value->value.lval = l;    \
  298.         return;                            \
  299.     }
  300. #define RETURN_DOUBLE(d) {                \
  301.         return_value->type = IS_DOUBLE;    \
  302.         return_value->value.dval = d;    \
  303.         return;                            \
  304.     }
  305. #define RETURN_STRING(s,duplicate) {    \
  306.         char *__s=(s);                    \
  307.         return_value->value.str.len = strlen(__s);    \
  308.         return_value->value.str.val = (duplicate?estrndup(__s,return_value->value.str.len):__s);    \
  309.         return_value->type = IS_STRING;    \
  310.         return;                            \
  311.     }
  312. #define RETURN_STRINGL(s,l,duplicate) {        \
  313.         char *__s=(s); int __l=l;            \
  314.         return_value->value.str.len = __l;    \
  315.         return_value->value.str.val = (duplicate?estrndup(__s,__l):__s);    \
  316.           return_value->type = IS_STRING;        \
  317.         return;                                \
  318.     }
  319.  
  320. #define RETURN_EMPTY_STRING() {                \
  321.         return_value->value.str.len = 0;      \
  322.         return_value->value.str.val = empty_string; \
  323.         return_value->type = IS_STRING;        \
  324.         return;                             \
  325.     }
  326.  
  327. #define RETURN_FALSE  { RETVAL_FALSE; return; }
  328. #define RETURN_TRUE   { RETVAL_TRUE; return; }
  329.  
  330. #define SET_VAR_STRING(n,v)    {                                                                                \
  331.                                 {                                                                            \
  332.                                     zval *var;                                                                \
  333.                                     char *str=(v); /* prevent 'v' from being evaluated more than once */    \
  334.                                                                                                             \
  335.                                     ALLOC_ZVAL(var);                                                        \
  336.                                     var->value.str.val = (str);                                                \
  337.                                     var->value.str.len = strlen((str));                                        \
  338.                                     var->type = IS_STRING;                                                    \
  339.                                     ZEND_SET_GLOBAL_VAR(n, var);                                            \
  340.                                 }                                                                            \
  341.                             }
  342.  
  343. #define SET_VAR_STRINGL(n,v,l)    {                                                        \
  344.                                     {                                                    \
  345.                                         zval *var;                                        \
  346.                                                                                         \
  347.                                         ALLOC_ZVAL(var);                                \
  348.                                         var->value.str.val = (v);                        \
  349.                                         var->value.str.len = (l);                        \
  350.                                         var->type = IS_STRING;                            \
  351.                                         ZEND_SET_GLOBAL_VAR(n, var);                    \
  352.                                     }                                                    \
  353.                                 }
  354.  
  355. #define SET_VAR_LONG(n,v)    {                                                            \
  356.                                 {                                                        \
  357.                                     zval *var;                                            \
  358.                                                                                         \
  359.                                     ALLOC_ZVAL(var);                                    \
  360.                                     var->value.lval = (v);                                \
  361.                                     var->type = IS_LONG;                                \
  362.                                     ZEND_SET_GLOBAL_VAR(n, var);                        \
  363.                                 }                                                        \
  364.                             }
  365.  
  366. #define SET_VAR_DOUBLE(n,v)    {                                                            \
  367.                                 {                                                        \
  368.                                     zval *var;                                            \
  369.                                                                                         \
  370.                                     ALLOC_ZVAL(var);                                    \
  371.                                     var->value.dval = (v);                                \
  372.                                     var->type = IS_DOUBLE;                                \
  373.                                     ZEND_SET_GLOBAL_VAR(n, var);                        \
  374.                                 }                                                        \
  375.                             }
  376.  
  377.  
  378. #define ZEND_SET_SYMBOL(symtable, name, var)                                        \
  379.     {                                                                                \
  380.         char *_name = (name);                                                        \
  381.                                                                                     \
  382.         ZEND_SET_SYMBOL_WITH_LENGTH(symtable, _name, strlen(_name)+1, var, 1, 0);    \
  383.     }
  384.  
  385. #define ZEND_SET_SYMBOL_WITH_LENGTH(symtable, name, name_length, var, _refcount, _is_ref)                \
  386.     {                                                                                                    \
  387.         zval **orig_var;                                                                                \
  388.                                                                                                         \
  389.         if (zend_hash_find(symtable, (name), (name_length), (void **) &orig_var)==SUCCESS                \
  390.             && PZVAL_IS_REF(*orig_var)) {                                                                \
  391.             (var)->refcount = (*orig_var)->refcount;                                                    \
  392.             (var)->is_ref = 1;                                                                            \
  393.                                                                                                         \
  394.             if (_refcount) {                                                                            \
  395.                 (var)->refcount += _refcount-1;                                                            \
  396.             }                                                                                            \
  397.             zval_dtor(*orig_var);                                                                        \
  398.             **orig_var = *(var);                                                                        \
  399.             FREE_ZVAL(var);                                                                                    \
  400.         } else {                                                                                        \
  401.             (var)->is_ref = _is_ref;                                                                    \
  402.             if (_refcount) {                                                                            \
  403.                 (var)->refcount = _refcount;                                                            \
  404.             }                                                                                            \
  405.             zend_hash_update(symtable, (name), (name_length), &(var), sizeof(zval *), NULL);            \
  406.         }                                                                                                \
  407.     }
  408.  
  409.  
  410. #define ZEND_SET_GLOBAL_VAR(name, var)                \
  411.     ZEND_SET_SYMBOL(&EG(symbol_table), name, var)
  412.  
  413. #define ZEND_SET_GLOBAL_VAR_WITH_LENGTH(name, name_length, var, _refcount, _is_ref)        \
  414.     ZEND_SET_SYMBOL_WITH_LENGTH(&EG(symbol_table), name, name_length, var, _refcount, _is_ref)
  415.  
  416. #define HASH_OF(p) ((p)->type==IS_ARRAY ? (p)->value.ht : (((p)->type==IS_OBJECT ? (p)->value.obj.properties : NULL)))
  417. #define ZVAL_IS_NULL(z) ((z)->type==IS_NULL)
  418.  
  419. #endif /* ZEND_API_H */
  420.  
  421. /*
  422.  * Local variables:
  423.  * tab-width: 4
  424.  * c-basic-offset: 4
  425.  * End:
  426.  */
  427.